<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="shortcut icon" href="zw.ico">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>testDemo</title>
<link rel="stylesheet" type="text/css" href="../../../theme/ztree/3.5.12/zTreeStyle/zTreeStyle.css"/>
<script src='jquery-1.4.4.min.js' type="text/javascript"></script>
<script type="text/javascript" src="jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="jquery.ztree.excheck-3.5.js"></script>
<style type="text/css">
html,body{
	width: 1200px;
	margin: 0 auto;
	background-color: #f0f0f0;
	font-size: 12px;
}
</style>
</head>
<body>

<div>
    <ul id="OrgTree" class="ztree"></ul>
    <ul id="treeDemo" class="ztree"></ul>
</div>
<button>切换选中2-2</button>

<script type="text/javascript">
$(function(){
	//例1
	var setting = {
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: 0
			}
		},
		
		callback:{
			onClick:function(event, treeId, treeNode){
				if(treeNode.isParent){
					return;
				}
				var orgId = treeNode.id;
				var orgName = treeNode.name;
				if( orgId == "-1"){
					orgId = "0";
				}
				if(confirm("是否需要切换登录到["+orgName+"]?")){
					var datas = "&orgId="+orgId + "&orgName="+orgName;
					alert(datas)
				}
			}
		}
	
	};

	var arr = [{"ISPARENT":"true","NAME":"舟山","PID":"0","ID":"580"},{"ISPARENT":"true","NAME":"定海","PID":"580","ID":"5801"},{"ISPARENT":"false","NAME":"舟山移动公司","PID":"5801","ID":"21"},{"ISPARENT":"true","NAME":"杭州","PID":"0","ID":"571"},{"ISPARENT":"true","NAME":"武林","PID":"571","ID":"5711"},{"ISPARENT":"false","NAME":"市场部终端管理中心","PID":"5711","ID":"10164189"},{"ISPARENT":"false","NAME":"市场部","PID":"5711","ID":"12011004"},{"ISPARENT":"false","NAME":"市场部","PID":"5711","ID":"12011004"},{"ISPARENT":"false","NAME":"中邮物流","PID":"5711","ID":"10164215"},{"ISPARENT":"false","NAME":"武林龙旋代理点","PID":"5711","ID":"10215359"},{"ISPARENT":"false","NAME":"杭州移动公司","PID":"5711","ID":"12"},{"ISPARENT":"false","NAME":"终端公司浙江分公司","PID":"5711","ID":"40015602"},{"ISPARENT":"false","NAME":"武林话机世界4S店卖场","PID":"5711","ID":"10030979"},{"ISPARENT":"false","NAME":"浙江移动总公司","PID":"5711","ID":"-1"},{"ISPARENT":"true","NAME":"销售部","PID":"571","ID":"571F"},{"ISPARENT":"false","NAME":"武林吴山营业厅","PID":"571F","ID":"12011016"},{"ISPARENT":"false","NAME":"武林元通大厦营业厅","PID":"571F","ID":"10030520"},{"ISPARENT":"true","NAME":"衢州","PID":"0","ID":"570"},{"ISPARENT":"true","NAME":"柯城","PID":"570","ID":"5701"},{"ISPARENT":"false","NAME":"衢州移动公司","PID":"5701","ID":"11"},{"ISPARENT":"true","NAME":"宁波","PID":"0","ID":"574"},{"ISPARENT":"true","NAME":"海曙","PID":"574","ID":"5741"},{"ISPARENT":"false","NAME":"宁波移动公司","PID":"5741","ID":"15"},{"ISPARENT":"true","NAME":"绍兴","PID":"0","ID":"575"},{"ISPARENT":"true","NAME":"绍兴","PID":"575","ID":"5751"},{"ISPARENT":"false","NAME":"绍兴移动公司","PID":"5751","ID":"16"},{"ISPARENT":"true","NAME":"湖州","PID":"0","ID":"572"},{"ISPARENT":"true","NAME":"吴兴","PID":"572","ID":"5721"},{"ISPARENT":"false","NAME":"湖州移动公司","PID":"5721","ID":"13"},{"ISPARENT":"true","NAME":"嘉兴","PID":"0","ID":"573"},{"ISPARENT":"true","NAME":"平湖","PID":"573","ID":"5735"},{"ISPARENT":"false","NAME":"嘉兴平湖曹桥营业厅","PID":"5735","ID":"10030964"},{"ISPARENT":"true","NAME":"嘉兴","PID":"573","ID":"5731"},{"ISPARENT":"false","NAME":"嘉兴嘉禾南汇营业厅","PID":"5731","ID":"10030963"},{"ISPARENT":"false","NAME":"嘉兴移动公司","PID":"5731","ID":"14"},{"ISPARENT":"false","NAME":"嘉兴斜西街营业厅","PID":"5731","ID":"1403101"},{"ISPARENT":"false","NAME":"（翀）29156(132-01)环驰手机大卖场","PID":"5731","ID":"10009649"},{"ISPARENT":"true","NAME":"嘉善","PID":"573","ID":"5734"},{"ISPARENT":"false","NAME":"嘉兴嘉善惠民营业厅","PID":"5734","ID":"10031073"},{"ISPARENT":"true","NAME":"丽水","PID":"0","ID":"578"},{"ISPARENT":"true","NAME":"南城","PID":"578","ID":"578B"},{"ISPARENT":"false","NAME":"丽水移动公司","PID":"578B","ID":"19"},{"ISPARENT":"true","NAME":"金华","PID":"0","ID":"579"},{"ISPARENT":"true","NAME":"婺城","PID":"579","ID":"5791"},{"ISPARENT":"false","NAME":"金华移动公司","PID":"5791","ID":"20"},{"ISPARENT":"true","NAME":"台州","PID":"0","ID":"576"},{"ISPARENT":"true","NAME":"椒江","PID":"576","ID":"5761"},{"ISPARENT":"false","NAME":"台州移动公司","PID":"5761","ID":"17"},{"ISPARENT":"true","NAME":"温州","PID":"0","ID":"577"},{"ISPARENT":"true","NAME":"鹿城","PID":"577","ID":"5771"},{"ISPARENT":"false","NAME":"温州移动公司","PID":"5771","ID":"18"}];

	var initData = [];
	if(arr != null){
		for(var i=0;i<arr.length;i++){
			var o={};
			o.id=arr[i].ID;
			o.pId=arr[i].PID;
			o.name=arr[i].NAME;
			o.isParent=arr[i].ISPARENT;
			initData.push(o);
		}
	}

	$.fn.zTree.init($("#OrgTree"), setting, initData);


	//例2
	var setting2 = {  
        check: {  
            enable: true  //是否启用 复选框  
        },  
        data: {  
            simpleData: {  
                enable: true  
            }  
        }  
    };  
    var zNodes =[  
        { id:1, pId:0, name:"随意勾选 1", open:true}, //pId 的 值就是上一级的id值  
        { id:11, pId:1, name:"随意勾选 1-1", open:true},  
        { id:111, pId:11, name:"随意勾选 1-1-1"},  
        { id:112, pId:11, name:"随意勾选 1-1-2"},  
        { id:12, pId:1, name:"随意勾选 1-2", open:true},  
        { id:121, pId:12, name:"随意勾选 1-2-1"},  
        { id:122, pId:12, name:"随意勾选 1-2-2"},  
        { id:2, pId:0, name:"随意勾选 2", open:true},  
        { id:21, pId:2, name:"随意勾选 2-1"},  
        { id:22, pId:2, name:"随意勾选 2-2", open:true},  
        { id:221, pId:22, name:"随意勾选 2-2-1"},  
        { id:222, pId:22, name:"随意勾选 2-2-2"},  
        { id:23, pId:2, name:"随意勾选 2-3"}  
    ];  
      
  
    $.fn.zTree.init($("#treeDemo"), setting2, zNodes);

    $("button").click(function(){
    	var id = '22';
    	var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
    	var node = treeObj.getNodeByParam("id", id, null, true);
    	treeObj.checkNode(node, null, false);
    })
});
</script>
</body>
</html>